package zpp_nape.phys;
import zpp_nape.Config;
import zpp_nape.Const;
import zpp_nape.util.Flags;
import DummyNapeMain;
import zpp_nape.util.Math;
import zpp_nape.util.Names;
import zpp_nape.util.Pool;
import zpp_nape.util.Lists;
import zpp_nape.shape.Circle;
import zpp_nape.shape.Edge;
import zpp_nape.space.Space;
import zpp_nape.shape.Polygon;
import zpp_nape.shape.Shape;
import zpp_nape.phys.FeatureMix;
import zpp_nape.phys.FluidProperties;
import zpp_nape.phys.Material;
import zpp_nape.geom.AABB;
import zpp_nape.geom.Distance;
import zpp_nape.geom.Mat23;
import zpp_nape.geom.Vec2;
import zpp_nape.geom.VecMath;
import zpp_nape.geom.Collide;
import zpp_nape.dynamics.Arbiter;
import zpp_nape.dynamics.Contact;
import zpp_nape.dynamics.InteractionFilter;
import zpp_nape.constraint.Constraint;
import zpp_nape.dynamics.SpaceArbiterList;
import zpp_nape.constraint.Matrices;
import zpp_nape.constraint.PivotJoint;
import zpp_nape.constraint.WeldJoint;
import nape.util.Flags;
import nape.util.Lists;
import nape.util.Debug;
import nape.space.Space;
import nape.shape.Circle;
import nape.shape.Polygon;
import nape.shape.Edge;
import nape.shape.Shape;
import nape.phys.FluidProperties;
import nape.phys.Material;
import nape.phys.Body;
import nape.geom.AABB;
import nape.geom.Geom;
import nape.geom.Mat23;
import nape.geom.Vec2;
import nape.dynamics.Contact;
import nape.dynamics.Arbiter;
import nape.dynamics.InteractionFilter;
#if swc@:keep#end class ZPP_Body{
    public var outer:Body;
    static var nextId=0;
    public var id:Int;
    public var type:Int;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function isStatic()return type==ZPP_Flags.id_BodyType_STATIC#if(flash9&&flib)@:ns("flibdel")#end public inline function isDynamic()return type==ZPP_Flags.id_BodyType_DYNAMIC#if(flash9&&flib)@:ns("flibdel")#end public inline function isKinematic()return type==ZPP_Flags.id_BodyType_KINEMATIC#if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_type(){
        invalidate_mass();
        invalidate_inertia();
    }
    public var shapes:ZNPList_ZPP_Shape;
    public var wrap_shapes:ShapeList;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_shapes(){
        invalidate_aabb();
        invalidate_localCOM();
        invalidate_mass();
        invalidate_inertia();
    }
    public var space:ZPP_Space;
    public var arbiters:ZNPList_ZPP_Arbiter;
    public var wrap_arbiters:ArbiterList;
    public var parent:ZPP_Body;
    public var rank:Int;
    public var island:ZPP_Island;
    public var sleeping:Bool;
    public var waket:Int;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function atRest(){
        if(!isDynamic())return sleeping;
        else{
            var cansleep=if((velx*velx+vely*vely)>ZPP_Config.SLEEP_LINEAR_SQ)false;
            else{
                var dx:Float;
                var dy:Float;
                {
                    dx=aabb.maxx-aabb.minx;
                    dy=aabb.maxy-aabb.miny;
                };
                4*angvel*angvel/(dx*dx+dy*dy)<ZPP_Config.SLEEP_ANGULAR_SQ;
            }
            if(!cansleep)waket=space.stamp;
            return waket+ZPP_Config.SLEEP_DELAY<space.stamp;
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function wake(){
        if(space!=null)space.wake(this);
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function wakeall(){
        if(space!=null){
            space.wake(this);
            space.wake_connected(this);
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function refreshArbiters(){
        {
            var cx_ite=arbiters.begin();
            while(cx_ite!=null){
                var arb=cx_ite.elem();
                {
                    arb.invalidated=true;
                };
                cx_ite=cx_ite.next;
            }
        };
    }
    public var posx:Float;
    public var posy:Float;
    public var wrap_pos:Vec2;
    public var velx:Float;
    public var vely:Float;
    public var wrap_vel:Vec2;
    public var forcex:Float;
    public var forcey:Float;
    public var wrap_force:Vec2;
    public var bias_velx:Float;
    public var bias_vely:Float;
    public var kinvelx:Float;
    public var kinvely:Float;
    public var pre_posx:Float;
    public var pre_posy:Float;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_pos(){
        {
            var cx_ite=shapes.begin();
            while(cx_ite!=null){
                var s=cx_ite.elem();
                {
                    if(s.type==ZPP_Flags.id_ShapeType_POLYGON){
                        s.polygon.invalidate_gverts();
                        s.polygon.invalidate_gaxi();
                    }
                    s.invalidate_worldCOM();
                };
                cx_ite=cx_ite.next;
            }
        };
        invalidate_worldCOM();
    }
    public function setupPosition(){
        var me=this;
        me.wrap_pos=new Vec2(posx,posy);
        me.wrap_pos.zpp_inner.inuse=true;
        me.wrap_pos.zpp_inner._invalidate=function(pos:ZPP_Vec2){
            if(me.isStatic()&&me.space!=null)throw "Error: Cannot move a static object once inside a Space";
            if(!(me.posx==pos.x&&me.posy==pos.y)){
                {
                    me.posx=pos.x;
                    me.posy=pos.y;
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](me.posx);
                                ret;
                                #else Math.isNaN(me.posx);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(me.posx)"+") :: "+("vec_set(in n: "+"me.pos"+",in x: "+"pos.x"+",in y: "+"pos.y"+")");
                        #end
                    };
                    {
                        #if NAPE_ASSERT var res={
                            !({
                                #if flash9 var ret:Bool=untyped __global__["isNaN"](me.posy);
                                ret;
                                #else Math.isNaN(me.posy);
                                #end
                            });
                        };
                        if(!res)throw "assert("+"!assert_isNaN(me.posy)"+") :: "+("vec_set(in n: "+"me.pos"+",in x: "+"pos.x"+",in y: "+"pos.y"+")");
                        #end
                    };
                };
                me.invalidate_pos();
                me.wakeall();
            }
        };
        me.wrap_pos.zpp_inner._validate=function(){
            me.wrap_pos.zpp_inner.x=me.posx;
            me.wrap_pos.zpp_inner.y=me.posy;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_pos.zpp_inner.x);
                        ret;
                        #else Math.isNaN(me.wrap_pos.zpp_inner.x);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(me.wrap_pos.zpp_inner.x)"+") :: "+("vec_set(in n: "+"me.wrap_pos.zpp_inner."+",in x: "+"me.posx"+",in y: "+"me.posy"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_pos.zpp_inner.y);
                        ret;
                        #else Math.isNaN(me.wrap_pos.zpp_inner.y);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(me.wrap_pos.zpp_inner.y)"+") :: "+("vec_set(in n: "+"me.wrap_pos.zpp_inner."+",in x: "+"me.posx"+",in y: "+"me.posy"+")");
                #end
            };
        };
    }
    public function setupVelocity(){
        var me=this;
        if(isKinematic())me.wrap_vel=new Vec2(kinvelx,kinvely);
        else me.wrap_vel=new Vec2(velx,vely);
        me.wrap_vel.zpp_inner.inuse=true;
        me.wrap_vel.zpp_inner._invalidate=function(vel:ZPP_Vec2){
            if(me.isKinematic()){
                me.kinvelx=vel.x;
                me.kinvely=vel.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.kinvelx);
                            ret;
                            #else Math.isNaN(me.kinvelx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.kinvelx)"+") :: "+("vec_set(in n: "+"me.kinvel"+",in x: "+"vel.x"+",in y: "+"vel.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.kinvely);
                            ret;
                            #else Math.isNaN(me.kinvely);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.kinvely)"+") :: "+("vec_set(in n: "+"me.kinvel"+",in x: "+"vel.x"+",in y: "+"vel.y"+")");
                    #end
                };
            };
            else{
                me.velx=vel.x;
                me.vely=vel.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.velx);
                            ret;
                            #else Math.isNaN(me.velx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.velx)"+") :: "+("vec_set(in n: "+"me.vel"+",in x: "+"vel.x"+",in y: "+"vel.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.vely);
                            ret;
                            #else Math.isNaN(me.vely);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.vely)"+") :: "+("vec_set(in n: "+"me.vel"+",in x: "+"vel.x"+",in y: "+"vel.y"+")");
                    #end
                };
            };
            if(!me.isStatic())me.invalidate_wake();
        };
        me.wrap_vel.zpp_inner._validate=function(){
            if(me.isKinematic()){
                me.wrap_vel.zpp_inner.x=me.kinvelx;
                me.wrap_vel.zpp_inner.y=me.kinvely;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_vel.zpp_inner.x);
                            ret;
                            #else Math.isNaN(me.wrap_vel.zpp_inner.x);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_vel.zpp_inner.x)"+") :: "+("vec_set(in n: "+"me.wrap_vel.zpp_inner."+",in x: "+"me.kinvelx"+",in y: "+"me.kinvely"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_vel.zpp_inner.y);
                            ret;
                            #else Math.isNaN(me.wrap_vel.zpp_inner.y);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_vel.zpp_inner.y)"+") :: "+("vec_set(in n: "+"me.wrap_vel.zpp_inner."+",in x: "+"me.kinvelx"+",in y: "+"me.kinvely"+")");
                    #end
                };
            };
            else{
                me.wrap_vel.zpp_inner.x=me.velx;
                me.wrap_vel.zpp_inner.y=me.vely;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_vel.zpp_inner.x);
                            ret;
                            #else Math.isNaN(me.wrap_vel.zpp_inner.x);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_vel.zpp_inner.x)"+") :: "+("vec_set(in n: "+"me.wrap_vel.zpp_inner."+",in x: "+"me.velx"+",in y: "+"me.vely"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_vel.zpp_inner.y);
                            ret;
                            #else Math.isNaN(me.wrap_vel.zpp_inner.y);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.wrap_vel.zpp_inner.y)"+") :: "+("vec_set(in n: "+"me.wrap_vel.zpp_inner."+",in x: "+"me.velx"+",in y: "+"me.vely"+")");
                    #end
                };
            };
        }
    }
    public function setupForce(){
        var me=this;
        me.wrap_force=new Vec2(forcex,forcey);
        me.wrap_force.zpp_inner._invalidate=function(force:ZPP_Vec2){
            {
                me.forcex=force.x;
                me.forcey=force.y;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.forcex);
                            ret;
                            #else Math.isNaN(me.forcex);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.forcex)"+") :: "+("vec_set(in n: "+"me.force"+",in x: "+"force.x"+",in y: "+"force.y"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](me.forcey);
                            ret;
                            #else Math.isNaN(me.forcey);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(me.forcey)"+") :: "+("vec_set(in n: "+"me.force"+",in x: "+"force.x"+",in y: "+"force.y"+")");
                    #end
                };
            };
            if(me.isDynamic())me.invalidate_wake();
        };
        me.wrap_force.zpp_inner.inuse=true;
        me.wrap_force.zpp_inner._validate=function(){
            me.wrap_force.zpp_inner.x=me.forcex;
            me.wrap_force.zpp_inner.y=me.forcey;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_force.zpp_inner.x);
                        ret;
                        #else Math.isNaN(me.wrap_force.zpp_inner.x);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(me.wrap_force.zpp_inner.x)"+") :: "+("vec_set(in n: "+"me.wrap_force.zpp_inner."+",in x: "+"me.forcex"+",in y: "+"me.forcey"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](me.wrap_force.zpp_inner.y);
                        ret;
                        #else Math.isNaN(me.wrap_force.zpp_inner.y);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(me.wrap_force.zpp_inner.y)"+") :: "+("vec_set(in n: "+"me.wrap_force.zpp_inner."+",in x: "+"me.forcex"+",in y: "+"me.forcey"+")");
                #end
            };
        };
    }
    public var angvel:Float;
    public var torque:Float;
    public var bias_angvel:Float;
    public var kinangvel:Float;
    public var pre_rot:Float;
    public var rot:Float;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_rot(){
        zip_axis=true;
        {
            var cx_ite=shapes.begin();
            while(cx_ite!=null){
                var s=cx_ite.elem();
                {
                    if(s.type==ZPP_Flags.id_ShapeType_POLYGON){
                        s.polygon.invalidate_gverts();
                        s.polygon.invalidate_gaxi();
                    }
                    s.invalidate_worldCOM();
                };
                cx_ite=cx_ite.next;
            }
        };
        invalidate_worldCOM();
    }
    public var axisx:Float;
    public var axisy:Float;
    public var zip_axis:Bool;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_axis(){
        if(zip_axis){
            zip_axis=false;
            {
                axisx=Math.sin(rot);
                axisy=Math.cos(rot);
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](axisx);
                            ret;
                            #else Math.isNaN(axisx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(axisx)"+") :: "+("vec_set(in n: "+"axis"+",in x: "+"Math.sin(rot)"+",in y: "+"Math.cos(rot)"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](axisy);
                            ret;
                            #else Math.isNaN(axisy);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(axisy)"+") :: "+("vec_set(in n: "+"axis"+",in x: "+"Math.sin(rot)"+",in y: "+"Math.cos(rot)"+")");
                    #end
                };
            };
        }
    }
    public var mass:Float;
    public var zip_mass:Bool;
    public var massMode:Int;
    public var imass:Float;
    public var smass:Float;
    public var cmass:Float;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_mass(){
        if(massMode==ZPP_Flags.id_MassMode_DEFAULT)zip_mass=true;
        invalidate_gravMass();
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_mass(){
        if(zip_mass){
            zip_mass=false;
            if(massMode==ZPP_Flags.id_MassMode_DEFAULT){
                cmass=0;
                {
                    var cx_ite=shapes.begin();
                    while(cx_ite!=null){
                        var s=cx_ite.elem();
                        {
                            s.validate_area_inertia();
                            cmass+=s.area*s.material.density;
                        };
                        cx_ite=cx_ite.next;
                    }
                };
                if(isDynamic()){
                    mass=cmass;
                    imass=smass=1.0/mass;
                }
                else{
                    mass=ZPP_Const.POSINF;
                    imass=smass=0.0;
                }
            }
        }
    }
    public var gravMass:Float;
    public var zip_gravMass:Bool;
    public var gravMassMode:Int;
    public var gravMassScale:Float;
    public var zip_gravMassScale:Bool;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_gravMass(){
        if(gravMassMode!=ZPP_Flags.id_GravMassMode_FIXED)zip_gravMass=true;
        if(gravMassMode!=ZPP_Flags.id_GravMassMode_SCALED)zip_gravMassScale=true;
        wake();
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_gravMass(){
        if(zip_gravMass){
            zip_gravMass=false;
            if(gravMassMode==ZPP_Flags.id_GravMassMode_DEFAULT){
                validate_mass();
                gravMass=mass;
            }
            else if(gravMassMode==ZPP_Flags.id_GravMassMode_SCALED){
                validate_mass();
                gravMass=mass*gravMassScale;
            }
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_gravMassScale(){
        if(gravMassMode!=ZPP_Flags.id_GravMassMode_SCALED)zip_gravMassScale=true;
        else invalidate_gravMass();
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_gravMassScale(){
        if(zip_gravMassScale){
            zip_gravMassScale=false;
            if(gravMassMode==ZPP_Flags.id_GravMassMode_DEFAULT)gravMassScale=1.0;
            else if(gravMassMode==ZPP_Flags.id_GravMassMode_FIXED){
                validate_mass();
                gravMassScale=gravMass/mass;
            }
        }
    }
    public var inertiaMode:Int;
    public var inertia:Float;
    public var zip_inertia:Bool;
    public var cinertia:Float;
    public var iinertia:Float;
    public var sinertia:Float;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_inertia(){
        if(inertiaMode!=ZPP_Flags.id_InertiaMode_FIXED)zip_inertia=true;
        wake();
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_inertia(){
        if(zip_inertia){
            zip_inertia=false;
            if(inertiaMode==ZPP_Flags.id_InertiaMode_DEFAULT){
                cinertia=0;
                {
                    var cx_ite=shapes.begin();
                    while(cx_ite!=null){
                        var s=cx_ite.elem();
                        {
                            s.validate_area_inertia();
                            cinertia+=s.inertia*s.area*s.material.density;
                        };
                        cx_ite=cx_ite.next;
                    }
                };
                if(isDynamic()){
                    inertia=cinertia;
                    sinertia=iinertia=1.0/inertia;
                }
                else{
                    inertia=ZPP_Const.POSINF;
                    sinertia=iinertia=0;
                }
            }
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_wake(){
        wake();
    }
    public var aabb:ZPP_AABB;
    public var zip_aabb:Bool;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_aabb(){
        if(zip_aabb){
            zip_aabb=false;
            {
                aabb.minx=ZPP_Const.POSINF;
                aabb.miny=ZPP_Const.POSINF;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](aabb.minx);
                            ret;
                            #else Math.isNaN(aabb.minx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(aabb.minx)"+") :: "+("vec_set(in n: "+"aabb.min"+",in x: "+"ZPP_Const.POSINF"+",in y: "+"ZPP_Const.POSINF"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](aabb.miny);
                            ret;
                            #else Math.isNaN(aabb.miny);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(aabb.miny)"+") :: "+("vec_set(in n: "+"aabb.min"+",in x: "+"ZPP_Const.POSINF"+",in y: "+"ZPP_Const.POSINF"+")");
                    #end
                };
            };
            {
                aabb.maxx=ZPP_Const.NEGINF;
                aabb.maxy=ZPP_Const.NEGINF;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](aabb.maxx);
                            ret;
                            #else Math.isNaN(aabb.maxx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(aabb.maxx)"+") :: "+("vec_set(in n: "+"aabb.max"+",in x: "+"ZPP_Const.NEGINF"+",in y: "+"ZPP_Const.NEGINF"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](aabb.maxy);
                            ret;
                            #else Math.isNaN(aabb.maxy);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(aabb.maxy)"+") :: "+("vec_set(in n: "+"aabb.max"+",in x: "+"ZPP_Const.NEGINF"+",in y: "+"ZPP_Const.NEGINF"+")");
                    #end
                };
            };
            {
                var cx_ite=shapes.begin();
                while(cx_ite!=null){
                    var s=cx_ite.elem();
                    {
                        s.validate_aabb();
                        aabb.combine(s.aabb);
                    };
                    cx_ite=cx_ite.next;
                }
            };
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_aabb(){
        zip_aabb=true;
    }
    public var localCOMx:Float;
    public var localCOMy:Float;
    public var zip_localCOM:Bool;
    public var worldCOMx:Float;
    public var worldCOMy:Float;
    public var zip_worldCOM:Bool;
    public var wrap_localCOM:Vec2;
    public var wrap_worldCOM:Vec2;
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_localCOM(){
        zip_localCOM=true;
        invalidate_worldCOM();
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function invalidate_worldCOM(){
        zip_worldCOM=true;
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_localCOM(){
        if(zip_localCOM){
            zip_localCOM=false;
            var tempx:Float=0;
            var tempy:Float=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](tempx);
                        ret;
                        #else Math.isNaN(tempx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(tempx)"+") :: "+("vec_new(in n: "+"temp"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](tempy);
                        ret;
                        #else Math.isNaN(tempy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(tempy)"+") :: "+("vec_new(in n: "+"temp"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            var msum=0.0;
            {
                var cx_ite=shapes.begin();
                while(cx_ite!=null){
                    var s=cx_ite.elem();
                    {
                        s.validate_localCOM();
                        s.validate_area_inertia();
                        {
                            var t=(s.area*s.material.density);
                            {
                                #if NAPE_ASSERT var res={
                                    !({
                                        #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                                        ret;
                                        #else Math.isNaN(t);
                                        #end
                                    });
                                };
                                if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_addeq(in a: "+"temp"+",in b: "+"s.localCOM"+",in s: "+"s.area*s.material.density"+")");
                                #end
                            };
                            tempx+=s.localCOMx*t;
                            tempy+=s.localCOMy*t;
                        };
                        msum+=s.area*s.material.density;
                    };
                    cx_ite=cx_ite.next;
                }
            };
            {
                var t=(1.0/(msum));
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](t);
                            ret;
                            #else Math.isNaN(t);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(t)"+") :: "+("vec_mul(in a: "+"temp"+",in s: "+"1.0/(msum)"+",out r: "+"localCOM"+")");
                    #end
                };
                localCOMx=tempx*t;
                localCOMy=tempy*t;
            };
            if(wrap_localCOM!=null){
                wrap_localCOM.zpp_inner.x=localCOMx;
                wrap_localCOM.zpp_inner.y=localCOMy;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](wrap_localCOM.zpp_inner.x);
                            ret;
                            #else Math.isNaN(wrap_localCOM.zpp_inner.x);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(wrap_localCOM.zpp_inner.x)"+") :: "+("vec_set(in n: "+"wrap_localCOM.zpp_inner."+",in x: "+"localCOMx"+",in y: "+"localCOMy"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](wrap_localCOM.zpp_inner.y);
                            ret;
                            #else Math.isNaN(wrap_localCOM.zpp_inner.y);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(wrap_localCOM.zpp_inner.y)"+") :: "+("vec_set(in n: "+"wrap_localCOM.zpp_inner."+",in x: "+"localCOMx"+",in y: "+"localCOMy"+")");
                    #end
                };
            };
            if(zip_mass&&massMode==ZPP_Flags.id_MassMode_DEFAULT){
                zip_mass=false;
                cmass=msum;
                if(isDynamic()){
                    mass=cmass;
                    imass=smass=1.0/mass;
                }
                else{
                    mass=ZPP_Const.POSINF;
                    imass=smass=0.0;
                }
            }
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function validate_worldCOM(){
        if(zip_worldCOM){
            zip_worldCOM=false;
            validate_localCOM();
            validate_axis();
            {
                worldCOMx=posx+(axisy*localCOMx-axisx*localCOMy);
                worldCOMy=posy+(localCOMx*axisx+localCOMy*axisy);
            };
            if(wrap_worldCOM!=null){
                wrap_worldCOM.zpp_inner.x=worldCOMx;
                wrap_worldCOM.zpp_inner.y=worldCOMy;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](wrap_worldCOM.zpp_inner.x);
                            ret;
                            #else Math.isNaN(wrap_worldCOM.zpp_inner.x);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(wrap_worldCOM.zpp_inner.x)"+") :: "+("vec_set(in n: "+"wrap_worldCOM.zpp_inner."+",in x: "+"worldCOMx"+",in y: "+"worldCOMy"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](wrap_worldCOM.zpp_inner.y);
                            ret;
                            #else Math.isNaN(wrap_worldCOM.zpp_inner.y);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(wrap_worldCOM.zpp_inner.y)"+") :: "+("vec_set(in n: "+"wrap_worldCOM.zpp_inner."+",in x: "+"worldCOMx"+",in y: "+"worldCOMy"+")");
                    #end
                };
            };
        }
    }
    public function getlocalCOM(){
        if(shapes.empty())throw "Error: localCOM only makes sense when Body has Shapes";
        validate_localCOM();
    }
    public function getworldCOM(){
        if(shapes.empty())throw "Error: worldCOM only makes sense when Body has Shapes";
        validate_worldCOM();
    }
    public function new(){
        {
            posx=0;
            posy=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](posx);
                        ret;
                        #else Math.isNaN(posx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(posx)"+") :: "+("vec_set(in n: "+"pos"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](posy);
                        ret;
                        #else Math.isNaN(posy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(posy)"+") :: "+("vec_set(in n: "+"pos"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        rot=0;
        {
            axisx=0;
            axisy=1;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](axisx);
                        ret;
                        #else Math.isNaN(axisx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(axisx)"+") :: "+("vec_set(in n: "+"axis"+",in x: "+"0"+",in y: "+"1"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](axisy);
                        ret;
                        #else Math.isNaN(axisy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(axisy)"+") :: "+("vec_set(in n: "+"axis"+",in x: "+"0"+",in y: "+"1"+")");
                #end
            };
        };
        {
            velx=0;
            vely=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](velx);
                        ret;
                        #else Math.isNaN(velx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(velx)"+") :: "+("vec_set(in n: "+"vel"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](vely);
                        ret;
                        #else Math.isNaN(vely);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(vely)"+") :: "+("vec_set(in n: "+"vel"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        {
            kinvelx=0;
            kinvely=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](kinvelx);
                        ret;
                        #else Math.isNaN(kinvelx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(kinvelx)"+") :: "+("vec_set(in n: "+"kinvel"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](kinvely);
                        ret;
                        #else Math.isNaN(kinvely);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(kinvely)"+") :: "+("vec_set(in n: "+"kinvel"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        {
            forcex=0;
            forcey=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](forcex);
                        ret;
                        #else Math.isNaN(forcex);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(forcex)"+") :: "+("vec_set(in n: "+"force"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](forcey);
                        ret;
                        #else Math.isNaN(forcey);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(forcey)"+") :: "+("vec_set(in n: "+"force"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        {
            bias_velx=0;
            bias_vely=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](bias_velx);
                        ret;
                        #else Math.isNaN(bias_velx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(bias_velx)"+") :: "+("vec_set(in n: "+"bias_vel"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](bias_vely);
                        ret;
                        #else Math.isNaN(bias_vely);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(bias_vely)"+") :: "+("vec_set(in n: "+"bias_vel"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        torque=angvel=bias_angvel=kinangvel=0;
        {
            pre_posx=ZPP_Const.POSINF;
            pre_posy=ZPP_Const.POSINF;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](pre_posx);
                        ret;
                        #else Math.isNaN(pre_posx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(pre_posx)"+") :: "+("vec_set(in n: "+"pre_pos"+",in x: "+"ZPP_Const.POSINF"+",in y: "+"ZPP_Const.POSINF"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](pre_posy);
                        ret;
                        #else Math.isNaN(pre_posy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(pre_posy)"+") :: "+("vec_set(in n: "+"pre_pos"+",in x: "+"ZPP_Const.POSINF"+",in y: "+"ZPP_Const.POSINF"+")");
                #end
            };
        };
        pre_rot=ZPP_Const.POSINF;
        {
            localCOMx=0;
            localCOMy=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](localCOMx);
                        ret;
                        #else Math.isNaN(localCOMx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(localCOMx)"+") :: "+("vec_set(in n: "+"localCOM"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](localCOMy);
                        ret;
                        #else Math.isNaN(localCOMy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(localCOMy)"+") :: "+("vec_set(in n: "+"localCOM"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        {
            worldCOMx=0;
            worldCOMy=0;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](worldCOMx);
                        ret;
                        #else Math.isNaN(worldCOMx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(worldCOMx)"+") :: "+("vec_set(in n: "+"worldCOM"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](worldCOMy);
                        ret;
                        #else Math.isNaN(worldCOMy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(worldCOMy)"+") :: "+("vec_set(in n: "+"worldCOM"+",in x: "+"0"+",in y: "+"0"+")");
                #end
            };
        };
        id=nextId++;
        zip_aabb=true;
        aabb=ZPP_AABB.get(0,0,0,0);
        aabb.immutable=true;
        var me=this;
        aabb._validate=function(){
            if(me.shapes.empty())throw "Error: bounds only makes sense when Body has Shapes";
            me.validate_aabb();
        };
        massMode=ZPP_Flags.id_MassMode_DEFAULT;
        gravMassMode=ZPP_Flags.id_GravMassMode_DEFAULT;
        gravMassScale=1.0;
        inertiaMode=ZPP_Flags.id_InertiaMode_DEFAULT;
        arbiters=new ZNPList_ZPP_Arbiter();
        shapes=new ZNPList_ZPP_Shape();
        wrap_shapes=ZPP_ShapeList.get(shapes);
        var me=this;
        wrap_shapes.zpp_inner.adder=function(s:Shape){
            if(s.zpp_inner.body!=me){
                if(s.zpp_inner.body!=null)s.zpp_inner.body.wrap_shapes.remove(s);
                s.zpp_inner.body=me;
                s.zpp_inner.addedToBody();
                if(me.space!=null)me.space.added_shape(s.zpp_inner);
                return true;
            }
            else return false;
        };
        wrap_shapes.zpp_inner.subber=function(s:Shape){
            if(me.space!=null)me.space.removed_shape(s.zpp_inner);
            s.zpp_inner.body=null;
            s.zpp_inner.removedFromBody();
        };
        wrap_shapes.zpp_inner._invalidate=function(_){
            me.invalidate_shapes();
        };
        wrap_shapes.zpp_inner._modifiable=function(){
            if(me.isStatic()&&me.space!=null)throw "Error: Cannot modifiy shapes of static object once added to Space";
        };
        parent=this;
        rank=0;
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function removedFromSpace(){
        while(!arbiters.empty()){
            var arb=arbiters.pop_unsafe();
            arb.lazyRetire(space,this);
        }
    }
    #if(flash9&&flib)@:ns("flibdel")#end public inline function copy(){
        var ret=new Body().zpp_inner;
        ret.type=type;
        {
            var cx_ite=shapes.begin();
            while(cx_ite!=null){
                var s=cx_ite.elem();
                {
                    var s2=Shape.copy(s.outer);
                    ret.outer.shapes.add(s2);
                };
                cx_ite=cx_ite.next;
            }
        };
        {
            ret.posx=posx;
            ret.posy=posy;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.posx);
                        ret;
                        #else Math.isNaN(ret.posx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.posx)"+") :: "+("vec_set(in n: "+"ret.pos"+",in x: "+"posx"+",in y: "+"posy"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.posy);
                        ret;
                        #else Math.isNaN(ret.posy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.posy)"+") :: "+("vec_set(in n: "+"ret.pos"+",in x: "+"posx"+",in y: "+"posy"+")");
                #end
            };
        };
        {
            ret.velx=velx;
            ret.vely=vely;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.velx);
                        ret;
                        #else Math.isNaN(ret.velx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.velx)"+") :: "+("vec_set(in n: "+"ret.vel"+",in x: "+"velx"+",in y: "+"vely"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.vely);
                        ret;
                        #else Math.isNaN(ret.vely);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.vely)"+") :: "+("vec_set(in n: "+"ret.vel"+",in x: "+"velx"+",in y: "+"vely"+")");
                #end
            };
        };
        {
            ret.forcex=forcex;
            ret.forcey=forcey;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.forcex);
                        ret;
                        #else Math.isNaN(ret.forcex);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.forcex)"+") :: "+("vec_set(in n: "+"ret.force"+",in x: "+"forcex"+",in y: "+"forcey"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.forcey);
                        ret;
                        #else Math.isNaN(ret.forcey);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.forcey)"+") :: "+("vec_set(in n: "+"ret.force"+",in x: "+"forcex"+",in y: "+"forcey"+")");
                #end
            };
        };
        if(!zip_axis){
            ret.axisx=axisx;
            ret.axisy=axisy;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.axisx);
                        ret;
                        #else Math.isNaN(ret.axisx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.axisx)"+") :: "+("vec_set(in n: "+"ret.axis"+",in x: "+"axisx"+",in y: "+"axisy"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.axisy);
                        ret;
                        #else Math.isNaN(ret.axisy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.axisy)"+") :: "+("vec_set(in n: "+"ret.axis"+",in x: "+"axisx"+",in y: "+"axisy"+")");
                #end
            };
        };
        else ret.invalidate_rot();
        ret.rot=rot;
        ret.massMode=massMode;
        ret.gravMassMode=gravMassMode;
        ret.inertiaMode=inertiaMode;
        if(!zip_mass)ret.mass=mass;
        else ret.invalidate_mass();
        if(!zip_gravMass)ret.gravMass=gravMass;
        else ret.invalidate_gravMass();
        if(!zip_gravMassScale)ret.gravMassScale=gravMassScale;
        else ret.invalidate_gravMassScale();
        if(!zip_inertia)ret.inertia=inertia;
        else ret.invalidate_inertia();
        if(!zip_aabb){
            {
                ret.aabb.minx=aabb.minx;
                ret.aabb.miny=aabb.miny;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.aabb.minx);
                            ret;
                            #else Math.isNaN(ret.aabb.minx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(ret.aabb.minx)"+") :: "+("vec_set(in n: "+"ret.aabb.min"+",in x: "+"aabb.minx"+",in y: "+"aabb.miny"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.aabb.miny);
                            ret;
                            #else Math.isNaN(ret.aabb.miny);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(ret.aabb.miny)"+") :: "+("vec_set(in n: "+"ret.aabb.min"+",in x: "+"aabb.minx"+",in y: "+"aabb.miny"+")");
                    #end
                };
            };
            {
                ret.aabb.maxx=aabb.maxx;
                ret.aabb.maxy=aabb.maxy;
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.aabb.maxx);
                            ret;
                            #else Math.isNaN(ret.aabb.maxx);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(ret.aabb.maxx)"+") :: "+("vec_set(in n: "+"ret.aabb.max"+",in x: "+"aabb.maxx"+",in y: "+"aabb.maxy"+")");
                    #end
                };
                {
                    #if NAPE_ASSERT var res={
                        !({
                            #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.aabb.maxy);
                            ret;
                            #else Math.isNaN(ret.aabb.maxy);
                            #end
                        });
                    };
                    if(!res)throw "assert("+"!assert_isNaN(ret.aabb.maxy)"+") :: "+("vec_set(in n: "+"ret.aabb.max"+",in x: "+"aabb.maxx"+",in y: "+"aabb.maxy"+")");
                    #end
                };
            };
        }
        else ret.invalidate_aabb();
        if(!zip_localCOM){
            ret.localCOMx=localCOMx;
            ret.localCOMy=localCOMy;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.localCOMx);
                        ret;
                        #else Math.isNaN(ret.localCOMx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.localCOMx)"+") :: "+("vec_set(in n: "+"ret.localCOM"+",in x: "+"localCOMx"+",in y: "+"localCOMy"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.localCOMy);
                        ret;
                        #else Math.isNaN(ret.localCOMy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.localCOMy)"+") :: "+("vec_set(in n: "+"ret.localCOM"+",in x: "+"localCOMx"+",in y: "+"localCOMy"+")");
                #end
            };
        };
        else ret.invalidate_localCOM();
        if(!zip_worldCOM){
            ret.worldCOMx=worldCOMx;
            ret.worldCOMy=worldCOMy;
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.worldCOMx);
                        ret;
                        #else Math.isNaN(ret.worldCOMx);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.worldCOMx)"+") :: "+("vec_set(in n: "+"ret.worldCOM"+",in x: "+"worldCOMx"+",in y: "+"worldCOMy"+")");
                #end
            };
            {
                #if NAPE_ASSERT var res={
                    !({
                        #if flash9 var ret:Bool=untyped __global__["isNaN"](ret.worldCOMy);
                        ret;
                        #else Math.isNaN(ret.worldCOMy);
                        #end
                    });
                };
                if(!res)throw "assert("+"!assert_isNaN(ret.worldCOMy)"+") :: "+("vec_set(in n: "+"ret.worldCOM"+",in x: "+"worldCOMx"+",in y: "+"worldCOMy"+")");
                #end
            };
        };
        else ret.invalidate_worldCOM();
        return ret.outer;
    }
}
